home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI2000 / TI2717.ASC < prev    next >
Text File  |  1994-10-03  |  3KB  |  118 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Pascal                                 NUMBER  :  2717
  8.   VERSION  :  All
  9.        OS  :  DOS
  10.      DATE  :  September 30, 1994                       PAGE  :  1/2
  11.  
  12.     TITLE  :  Using your EXE as a resource file
  13.  
  14.  
  15.  
  16.  
  17. {
  18.   This program demonstrates how to use your EXE 
  19.   file as a resource.  You should run this program
  20.   twice - once to write info to the EXE and once to
  21.   read info out.
  22. }
  23.  
  24. program foo;
  25.  
  26. uses Objects;
  27.  
  28. type
  29.   PMyObject = ^TMyObject;
  30.   TMyObject = object(TObject)
  31.     AString: String;
  32.     constructor Init(S: String);
  33.     constructor Load(var S: TStream);
  34.     procedure Store(var S: TStream);
  35.   end;
  36.  
  37. constructor TMyObject.Init(S: String);
  38. begin
  39.   inherited Init;
  40.   AString := S;
  41. end;
  42.  
  43. constructor TMyObject.Load(var S: TStream);
  44. begin
  45.   inherited Init;
  46.   S.Read(AString, SizeOf(AString));
  47. end;
  48.  
  49. procedure TMyObject.Store(var S: TStream);
  50. begin
  51.   S.Write(AString, SizeOf(AString));
  52. end;
  53.  
  54. const
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   PRODUCT  :  Pascal                                 NUMBER  :  2717
  68.   VERSION  :  All
  69.        OS  :  DOS
  70.      DATE  :  September 30, 1994                       PAGE  :  2/2
  71.  
  72.     TITLE  :  Using your EXE as a resource file
  73.  
  74.  
  75.  
  76.  
  77.   RMyObject: TStreamRec = (
  78.     ObjType: 100;
  79.     VmtLink: Ofs(TypeOf(TMyObject)^);
  80.     Load: @TMyObject.Load;
  81.     Store: @TMyObject.Store);
  82.  
  83. var
  84.   Rez: PResourceFile;
  85.   TheStream: PBufStream;
  86.   AObject, Obj: PMyObject;
  87.  
  88. begin
  89.    { Register my object for streaming } 
  90.   RegisterType(RMyObject);
  91.    { Create instace of my object } 
  92.   Obj := New(PMyObject, Init('Hello world'));
  93.    { Create instance of a stream pointing to EXE file } 
  94.   TheStream := New(PBufStream, Init(ParamStr(0), stOpen, 1024));
  95.    { was stream created okay? } 
  96.   if TheStream^.Status = stOk then begin
  97.    { Crate instance of resource file } 
  98.     Rez := New(PResourceFile, Init(TheStream));
  99.    { try to grab object from resource stream } 
  100.     AObject := PMyObject(Rez^.Get('My Object'));
  101.     if AObject <> nil then
  102.    {  if found, then write object's string to screen } 
  103.       writeln('The magic string is: ' + AObject^.AString)
  104.     else
  105.    { if not, then write object to resource } 
  106.       Rez^.Put(Obj, 'My Object');
  107.   end;
  108.    { clean up } 
  109.   Obj^.Free;
  110.   Rez^.Free;
  111. end.
  112.  
  113.  
  114. DISCLAIMER: You have the right to use this technical information
  115. subject to the terms of the No-Nonsense License Statement that
  116. you received with the Borland product to which this information
  117. pertains.
  118.